<template>
  <div
    :class="[active && 'is-active']"
    class="common-category-item"
    @tap="onSelect"
  >
    <div class="common-category-item__label">
      <span>{{ label }}</span>
    </div>
    <template v-if="active">
      <div v-if="index !== 0" class="common-category-item__left" />
      <div class="common-category-item__right" />
    </template>
  </div>
</template>

<script setup lang="ts">
defineOptions({
  name: "common-category-item",
});

const props = withDefaults(
  defineProps<{
    label: string;
    value: string;
    index: number;
    active: boolean;
  }>(),
  {}
);

const emits = defineEmits(["select"]);

const onSelect = () => {
  emits("select", props.value);
};
</script>

<style lang="less">
.common-category-item {
  --radial-size: 30px;
  --category-item-bg-color: #fff;
  position: relative;
  background-color: transparent;
  color: #8b8b8b;
  border-radius: 30px 30px 0 0;
  &.is-active {
    background-color: var(--category-item-bg-color);
    color: #000;
  }

  &__label {
    padding: 13px 30px;
    font-weight: bold;
    font-size: 30px;

    line-height: 50px;
    box-sizing: border-box;
  }

  &__left,
  &__right {
    position: absolute;
    width: var(--radial-size);
    height: var(--radial-size);
    bottom: 0;
  }
  &__left {
    left: calc(var(--radial-size) * -1);
    background: radial-gradient(
      circle at 0 0,
      transparent var(--radial-size),
      var(--category-item-bg-color) calc(var(--radial-size) + 1px)
    );
  }
  &__right {
    right: calc(var(--radial-size) * -1);
    background: radial-gradient(
      circle at 100% 0,
      transparent var(--radial-size),
      var(--category-item-bg-color) calc(var(--radial-size) + 1px)
    );
  }
}
</style>
